package com.huasoft.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBConnection {
	private static String url = "jdbc:mysql://localhost:3306/zheng?useUnicode=true&characterEncoding=gbk";
	private static String username = "root";
	private static String password = "123456";

	// 只执行一次
	static {
		// 加载驱动
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection() throws SQLException {
		return DriverManager.getConnection(url, username, password);
	}

	public static void closeConnection(Connection con, Statement st,
			ResultSet rs) throws SQLException {
		if (st != null)
			st.close();
		if (con != null)
			con.close();
		if (rs != null)
			rs.close();
	}

}
